//
//  ThreeDBettingViewController.m
//  WangLottery
//
//  Created by 黄修勇 on 12-4-26.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "ThreeDBettingViewController.h"
#import "CXSegmentControl.h"
#import <QuartzCore/QuartzCore.h>

@interface ThreeDBettingViewController ()

@property (nonatomic,retain) UIView *visibleView;
@property (nonatomic,assign) NSInteger currentViewMark;


@end

@implementation ThreeDBettingViewController

@synthesize buttonBackView=_buttonBackView;
@synthesize visibleView=_visibleView;
@synthesize currentViewMark=_currentViewMark;

-(void)dealloc{

    [viewsArray release];
    [_buttonBackView release];
    [_visibleView release];
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.hidesBottomBarWhenPushed=YES;
    }
    return self;
}

- (void)viewDidLoad
{
    
    [super viewDidLoad];
    
    _currentViewMark=0;
    
    NSArray *tempArray=[[NSArray alloc]initWithObjects:@"直选",@"组三",@"组六", nil];
    CXSegmentControl *segmentControl=[[CXSegmentControl alloc]initwithItem:tempArray];
    [tempArray release];
    segmentControl.frame=CGRectMake(10.0f, 15.0f, self.view.frame.size.width-20.0f, 28.0f);
    [self.view addSubview:segmentControl];
    [segmentControl addTarget:self action:@selector(segmentChange:) forControlEvents:UIControlEventValueChanged];
    [segmentControl release];
    
    ThreeDDirectView * directView=[[ThreeDDirectView alloc]initWithFrame:CGRectMake(10.0f, 15.0f+25.0f, self.view.frame.size.width-20.0f, 300.0f)];
    self.visibleView=directView;
    
    Three3DGroup *sanZu=[[Three3DGroup alloc]initWithFrame:directView.frame andLotteryType:Three3DGroupTypeSan];
    Three3DGroup *liuZu=[[Three3DGroup alloc]initWithFrame:directView.frame andLotteryType:Three3DGroupTypeLiu];
    
    viewsArray=[[NSArray alloc]initWithObjects:directView,sanZu,liuZu, nil];
    
    self.buttonBackView.layer.cornerRadius=8;
    self.buttonBackView.layer.backgroundColor=[UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:0.4f].CGColor;
    //Do any additional setup after loading the view from its nib.
    
}


-(void)segmentChange:(CXSegmentControl *)segmentControl{

    _currentViewMark=segmentControl.selectIndex;
    self.visibleView=[viewsArray objectAtIndex:segmentControl.selectIndex];
    
}

-(void)setVisibleView:(UIView *)visibleView{

    if ([visibleView isEqual:_visibleView]) {
        return;
    }
    [_visibleView removeFromSuperview];
    _visibleView=[visibleView retain];
    [self.view insertSubview:_visibleView atIndex:1];
    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark -userAction

- (IBAction)randomSelect:(id)sender
{
    
   id  v=[viewsArray objectAtIndex:_currentViewMark];
 
    if ([v isKindOfClass:[ThreeDDirectView class]]) {
        
        ThreeDDirectView *direct=(ThreeDDirectView *)v;
        [direct randomSelect3Direct];
        
        
    }
    else if([v isKindOfClass:[Three3DGroup class]]){
    
        Three3DGroup *group=(Three3DGroup *)v;
        
        [group randomSelect3Direct];
        
        
    }
    

}

@end
